package com.headStorm.doctuil;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.word.DocUtil;
import cn.hutool.poi.word.Word07Writer;

import java.awt.*;
import java.util.*;
import java.util.List;

/**
 * @author zhangqq
 * @create 2021-10-19 14:28
 **/
public class HutoolDocUtilDemo {

    public static void main(String[] args) {

        Word07Writer writer = new Word07Writer();
        // 添加段落（标题）
        writer.addText(new Font("方正小标宋简体", Font.PLAIN, 22), "我是第一部分", "我是第二部分");
        // 添加段落（正文）
        writer.addText(new Font("宋体", Font.PLAIN, 22), "我是正文第一部分", "我是正文第二部分");

        Map<String, String> map = new HashMap<>();
        map.put("name", "zhangqq");
        map.put("sex", "nan");

        Map<String, Object> row1 = new LinkedHashMap<>();
        row1.put("姓名", "张三");
        row1.put("年龄", 23);
        row1.put("成绩", 88.32);
        row1.put("是否合格", true);
        row1.put("考试日期", DateUtil.date());

        Map<String, Object> row2 = new LinkedHashMap<>();
        row2.put("姓名", "李四");
        row2.put("年龄", 33);
        row2.put("成绩", 59.50);
        row2.put("是否合格", false);
        row2.put("考试日期", DateUtil.date());
        ArrayList<Map<String, Object>> rows = CollUtil.newArrayList(row1, row2);

        writer.addTable(rows);
        // 写出到文件
        writer.flush(FileUtil.file("d:/wordWrite.docx"));
        // 关闭
        writer.close();
    }
}
